package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Stock;
import cn.wolfcode.trip.base.mapper.StockMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IStockService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StockServiceImpl implements IStockService {

    @Autowired
    private StockMapper stockMapper;

    @Override
    public void saveOrUpdate(Stock stock) {
        if (stock.getId()!=null){
            stockMapper.update(stock);
        }else {
            stockMapper.insert(stock);
        }
    }

    @Override
    public PageInfo query(QueryObject queryObject) {
        PageHelper.startPage(queryObject.getCurrentPage(),queryObject.getPageSize());
        List<Stock> list=stockMapper.selectAll();
        return new PageInfo(list);
    }

    /**
     * 得到商品的库存数量
     * @param id
     * @return
     */
    @Override
    public Stock selectStockNumber(Long id) {
        return stockMapper.selectStockNumber(id);
    }

    /**
     * 更新商品库存的数量
     * @param stock
     */
    @Override
    public void updateNumber(Stock stock) {
        stockMapper.updateNumber(stock);
    }


}
